﻿using Inovout.Kuajing.Exports.Models;
using Inovout.Organizations.Models;
using Inovout.Services;
using NHibernate.Criterion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Inovout.Kuajing.Exports.Services
{
    public class DrawerService : RepositoryService<Drawer>, IDrawerService
    {
        public List<Drawer> FindByKey(string key, OrganizationUnit organizationUnit)
        {
            if (organizationUnit != null)
            {
                return (List<Drawer>)base.Repository.FindAll(Restrictions.Eq("Organization.Id", (object)organizationUnit.Id));
            }
            else
            {
                IRepositoryService<Drawer> employeeService = ComponentRegistry.Resolve<IRepositoryService<Drawer>>();
                return employeeService.Query().ToList<Drawer>();
            }
        }

        public List<Drawer> FindByExporter(string key, Exporter exporter) 
        {
            if (exporter != null)
            {
                return (List<Drawer>)base.Repository.FindAll(Restrictions.Eq("Exporter.Id", (object)exporter.Id));
            }
            else
            {
                IRepositoryService<Drawer> employeeService = ComponentRegistry.Resolve<IRepositoryService<Drawer>>();
                return employeeService.Query().ToList<Drawer>();
            }
        }
    }
}
